<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title>来电显示多用户</title>
    </head>
    <body>
        <div id="customersgrid" style="height:130px;" class="x-form-item">
            来电<%=@phone_number %>对应以下客户：
        </div>
        <script>
            Ext.onReady(function(){
                var customercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
                    header: '编号',
                    dataIndex: 'id'
                }, {
                    header: '姓名',
                    dataIndex: 'name'
                }, {
                    header: '客户类型',
                    dataIndex: 'customer_type'
                }, {
                    header: '称呼',
                    dataIndex: 'sex',
                    renderer: renderSex
                }]);
                
                function renderSex(value){
                    if (value == '男') {
                        return "<span style='color:red;font-weight:bold;'>先生</span><img src='/images/male.gif' />";
                    }
                    else {
                        return "<span style='color:green;font-weight:bold;'>女士</span><img src='/images/female.gif' />";
                    }
                }
                //隐藏系统编号
                customercm.setHidden(1, !customercm.isHidden(1));
                var customerds = new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({
                        url: '/customers/getCustomersByPhoneNo?phone_number=<%=@phone_number%>'
                    }),
                    reader: new Ext.data.JsonReader({
                        totalProperty: 'totalProperty',
                        root: 'root'
                    }, [{
                        name: 'id'
                    }, {
                        name: 'name'
                    }, {
                        name: 'customer_type'
                    }, {
                        name: 'sex'
                    }])
                });
                
                var customergridpanel = new Ext.grid.GridPanel({
                    el: 'customersgrid',
                    ds: customerds,
                    cm: customercm,
                    //sm: sm,
                    loadMask: true
                });
                customergridpanel.render();
                //ds.load();
                customerds.load();
                
                //------------DBL Event For OrderGrid----------------------------------------
                customergridpanel.on('rowdblclick', function(customergridpanel, rowIndex, e){
                    var customersrow = customerds.getById(customerds.data.items[rowIndex].id);//ds为绑定到grid的数据源 
                    var customerid = customersrow.get("id");
                    window.document.location.href = "/index/phoneshow?id=" + customerid + "&phone_number=<%=@phone_number%>";
                });
                
            });
        </script>
    </body>
</html>
